package com.bjbn.tasks;

import com.bjbn.config.SystemConfig;
import com.bjbn.service.FimsDataService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 数据清理定时任务
 * 
 * @author bjbn
 */
@Slf4j
@Component
public class DataCleanupTask {

    @Autowired
    private SystemConfig systemConfig;

    @Autowired
    private FimsDataService fimsDataService;

    /**
     * 每天凌晨2点执行数据清理任务
     */
    @Scheduled(cron = "0 0 2 * * ?")
    public void cleanupExpiredData() {

        // 检查是否为TAOM模式
        if (!"taom".equals(systemConfig.getMode())) {
            log.info("当前不是TAOM模式，跳过清理数据");
            return;
        }

        log.debug("开始执行数据清理任务...");
        try {
            int deletedCount = fimsDataService.cleanExpiredData();
            log.debug("数据清理任务执行完成，删除记录数: {}", deletedCount);
        } catch (Exception e) {
            log.error("数据清理任务执行失败", e);
        }
    }
} 